﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel;

namespace Artech.EnterLibExt.ExceptionHandling.Configuration
{
    public class DomainFilterData: PropertyComparisonFilterData
    {
        private const string IgnoreCasePropertyName = "ignoreCase";
        private const string ValuesPropertyName = "values";

        [ConfigurationProperty(IgnoreCasePropertyName, IsRequired = false, DefaultValue = false)]
        public bool IgnoreCase
        {
            get { return (bool)this[IgnoreCasePropertyName]; }
            set { this[IgnoreCasePropertyName] = value; }
        }

        [ConfigurationProperty(ValuesPropertyName, IsRequired = true)]
        public string Values
        {
            get { return (string)this[ValuesPropertyName]; }
            set { this[ValuesPropertyName] = value; }
        }

        public override IEnumerable<TypeRegistration> GetRegistrations(string namePrefix)
        {
            yield return new TypeRegistration<IExceptionFilter>(() => new DomainFilter(this.Property, this.Values, this.IgnoreCase))
            {
                Name = this.BuildName(namePrefix),
                Lifetime = TypeRegistrationLifetime.Transient
            };   
        }
    }
}
